package urfave

import (
	io_urfave "clean/adapter/io/console/urfave"
	"clean/infra/config"
	"clean/infra/io"
	"clean/infra/io/driver"
	"clean/usecase"

	"os"

	"github.com/urfave/cli/v2"
)

type ioDriver struct {
}

func init() {
	io.Register("console_urfave", &ioDriver{})
}

func (ioDriver) Create(cfg config.Config, app usecase.Input) (io_driver.Io, error) {
	return NewServerUrfave(cfg, app)
}

// cw hello --name aa
type ServerUrfave struct {
	root *cli.App
}

func NewServerUrfave(cfg config.Config, app usecase.Input) (*ServerUrfave, error) {
	s := &ServerUrfave{
		root: &cli.App{
			Usage: "welcome App",
		},
	}
	h := io_urfave.NewHandler(app)
	h.Init(s.root)
	return s, nil
}

func (s *ServerUrfave) Start() error {
	return s.root.Run(os.Args)
}
